package com.fm._2work;

import com.fm.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.Scanner;

public class SendMsg {
    public static void main(String[] args) throws Exception {
        System.out.println("请输⼊消息：");
        Scanner scanner = new Scanner(System.in);
        String msg = null;
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("queue2", false, false, false, null);
        while (!"quit".equals(msg = scanner.nextLine())) {
            channel.basicPublish("", "queue2", null, msg.getBytes());
            System.out.println("发送：" + msg);
        }
        channel.close();
        connection.close();
    }
}